package org.learnaholic.application.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;


public class TestResultLog extends TreeMap<Date, TestResult>
{

	private final List<TestResultListener> listeners = new ArrayList<TestResultListener>();
	/**
	 * @param l
	 */
	public void addTestResultListener(TestResultListener l)
	{
		listeners.add(l);
	}

	/**
	 * @param l
	 */
	public void removeTestResultListener(TestResultListener l)
	{
		listeners.remove(l);
	}
	public TestResult put(Date key, TestResult value)
	{
		TestResult ret = super.put(key, value);
		notifyChange();
		return ret;
	}

	private void notifyChange()
	{
		TestResultEvent evt = new TestResultEvent(this);
		synchronized (listeners)
		{
			for (Iterator<TestResultListener> iterator = listeners.iterator(); iterator.hasNext();)
			{
				iterator.next().logChanged(evt);
			}
		}
	}
}
